﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Configuration;

namespace _4591BRD
{
    class Log
    {
        protected static int OutputLevel
        {
            get
            {
                int ret = 1;
                int.TryParse(ConfigurationSettings.AppSettings["LogLevel"].ToString(), out ret);
                return ret;
            }
        }

        public static void WriteError(string str)
        {
            string outLine = "\n--------------------------------------------------------------\n";
            outLine += "[" + DateTime.Now.ToString() + "] " + str;
            outLine += "\n--------------------------------------------------------------\n";

            if (Common.IsConsole)
                Console.WriteLine(outLine);
            //Trace.Listeners["errListener"].WriteLine("\n" + outLine);

            Trace.Listeners["logListener"].WriteLine(outLine);
        }

        public static void WriteLineNoDate(int logLevel, string str)
        {
            if (logLevel <= OutputLevel)
            {
                string outLine = str;

                if (Common.IsConsole)
                    Console.WriteLine(outLine);
                Trace.Listeners["logListener"].WriteLine(outLine);
            }
        }

        public static void WriteLine(int logLevel, string str)
        {
            if (logLevel <= OutputLevel)
            {
                string outLine = "[" + DateTime.Now.ToString() + "] " + str;

                if (Common.IsConsole)
                    Console.WriteLine(outLine);
                Trace.Listeners["logListener"].WriteLine(outLine);
            }
        }

        public static void Write(int logLevel, string str)
        {
            if (logLevel <= OutputLevel)
            {
                string outLine = str;

                if (Common.IsConsole)
                    Console.Write(outLine);
                Trace.Listeners["logListener"].Write(outLine);
            }
        }
    }
}
